package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.PurchaseList;
import com.atguigu.jxc.entity.User;
import com.atguigu.jxc.service.PurchaseListService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;

@RequestMapping("/purchaseListGoods")
@RestController
public class PurchaseController {
    @Autowired
    private PurchaseListService purchaseListService;
    //http://localhost:8080/purchaseListGoods/save?purchaseNumber=JH1660906174732
    @PostMapping("save")
    public ServiceVO save(@RequestParam String purchaseNumber,PurchaseList purchaseList,String purchaseListGoodsStr, HttpServletRequest request){
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("currentUser");
        purchaseList.setPurchaseNumber(purchaseNumber);
        purchaseList.setUserId(user.getUserId());
        return purchaseListService.save(purchaseList,purchaseListGoodsStr);
    }
    //http://localhost:8080/purchaseListGoods/list
    @RequestMapping("list")
    public Map<String,Object> list(String purchaseNumber, Integer supplierId, Integer state, String sTime,String eTime) {
                return purchaseListService.list(purchaseNumber,supplierId,state,sTime,eTime);
    }
    @RequestMapping("goodsList")
    public Map<String,Object> goodsList(Integer purchaseListId) {
        return purchaseListService.goodsList(purchaseListId);
    }
    @RequestMapping("delete")
    public ServiceVO deleteByPurchaseListId(Integer purchaseListId){
        return purchaseListService.deleteByPurchaseListId(purchaseListId);
    }

}

